﻿<?php
/*
 *    A Part of snock project
 *       Author king-of-war
 *      Last modified 2009-4-6
 */
@session_start();
$title='liujie';
error_reporting(E_ALL^E_NOTICE);//去除变量为空时的错误
$root_path='../';
include_once $root_path.'admin/smarty_config.php';
include_once $root_path.'admin/class/verify.class.php';
include_once $root_path.'admin/class/news.class.php';
include_once $root_path.'admin/class/error.class.php';

$news=new news($root_path);
$check=new verify($root_path);
$check->identity_check(2);
$error=new Errmsg();
/*
 *    define file upload moudle
 *
 *
 */




if(isset($_POST['upload'])){
	if(is_uploaded_file($_FILES['upfile']['tmp_name'])){
		$upfile=$_FILES['upfile'];
		$name=$upfile['name'];
		$type=$upfile['type'];
		$size=$upfile['size'];
		$tmp_name=$upfile['tmp_name'];

		switch($type){
			case 'image/pjpeg': $ok=1;
			break;
			case 'image/jpeg': $ok=1;
			break;
			case 'image/gif': $ok=1;
			break;
			case 'image/png': $ok=1;
			break;
			default: $ok=0;
			break;
		}
		if($ok){
if (file_exists('../images/uploads/'.$name)) {
echo '不能重复上传文件！';
}
			move_uploaded_file      ($tmp_name,'../images/uploads/'.$name);
			if($upfile['error']==0){
				$dir='images/uploads/'.$name;
				$image=$dir;
                                echo '上传成功';
			}else{
				echo '上传失败，请检查目录权限';}

		}else{
			echo '不允许此文件类型';}
	}
	/*
	 * define  news add function
	 */
}elseif(isset($_POST['submit'])){
	$title=$_POST['title'];
	$comments=$_POST['comments'];
	$author=$_POST['author'];
	$verify=$_POST['verify'];
	$pic=$_POST['image'];
   $bool = $news->news_add(null,$title,$pic,$comments,$author,$verify,1);
   if($bool){
       $info='新闻添加成功';
$error->error_chinese($info);
exit;
   }else{
     $info='添加失败，请检查输入';
$error->error_chinese($info);
exit;
   }
}
    /*
	 * define  news read function
	 */


/*
 *
 *    define FCKeditor
 */
if(!isset($dir)){
	$dir='空';
}
$smarty->assign("title",$title);
$smarty->assign("dir",$dir);
$smarty->display("news.html");
?>